﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skyworth.CRM.Common;
using Skyworth.CRM.Service.IBLL;

namespace Skyworth.CRM.Web.SalesManagement
{
    public partial class EditCustomerMoney : BasePage
    {
        IWeekLongBLL weekLongBLL = IocContainer.Instance.Resolve<IWeekLongBLL>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int empId = 0;
                int.TryParse(Request.QueryString["EmpId"], out empId);
                if (empId > 0)
                {
                    DataTable dt = weekLongBLL.QueryCustomerMoney(" and  a.Fitemid=" + empId);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        this.lbCustomerCode.Text = dt.Rows[0]["FNumber"].ToString();
                        this.lbCustomerName.Text = dt.Rows[0]["FName"].ToString();
                        this.lbAddress.Text = dt.Rows[0]["FDree"].ToString();
                        this.lbMobil.Text = dt.Rows[0]["FMobil"].ToString();
                        this.txtFCashAmount.Text = dt.Rows[0]["FCashAmount"].ToString();
                        this.txtFcreditAmount.Text = dt.Rows[0]["FcreditAmount"].ToString();
                    }
                }

            }

        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Boolean isOK = false;

                int empId = 0;
                //int customerid = 0;
                int.TryParse(Request.QueryString["EmpId"], out empId);
                //int.TryParse(Request.QueryString["cid"], out customerid);
                weekLongBLL.UpdateMoney(empId, Convert.ToDecimal(this.txtFCashAmount.Text.Trim()), Convert.ToDecimal(this.txtFcreditAmount.Text.Trim()));
                isOK = true;


                if (isOK)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "closeThisPage", "<script language=\"JavaScript\">parent.addWindow.close();parent.location.href = parent.location.href;</script>");
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Error(exception);
                Alert("发生异常：\r\n" + exception.Message);
            }
        }

    }
}
